package memory.GUI;


import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import memory.GameDifficulty;

/**
 *
 * @author Scott Robinson
 */
public class SizePrompt extends JFrame {

    private JRadioButton simple;
    private JRadioButton easy;
    private JRadioButton medium;
    private JRadioButton hard;
    private ButtonGroup options;
    private ButtonHandler buttonHandler;

    private JPanel optionPanel;
    private JPanel displayPanel;
    private JFrame frame;
    private final ImagePanel imagePanel;

    private JButton beginButton;


    private final int WIDTH = 600;
    private final int HEIGHT = 800;
    

    public SizePrompt (String str) {
        super(str);

        imagePanel = new ImagePanel();
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        this.add(imagePanel);

        simple = new JRadioButton("Simple");
        simple.setSelected(true);
        easy = new JRadioButton("Easy");
        medium = new JRadioButton("Medium");
        hard = new JRadioButton("Hard");
        beginButton = new JButton("Begin Game");

        options = new ButtonGroup();
        options.add(simple);
        options.add(easy);
        options.add(medium);
        options.add(hard);

        imagePanel.setLayout(new BorderLayout());

        optionPanel = new JPanel();
        displayPanel = new JPanel();

        optionPanel.add(simple);
        optionPanel.add(easy);
        optionPanel.add(medium);
        optionPanel.add(hard);

        displayPanel.setLayout(new BorderLayout());
        displayPanel.add(optionPanel, BorderLayout.NORTH);
        displayPanel.add(beginButton, BorderLayout.SOUTH);

        this.add(displayPanel, BorderLayout.SOUTH);

        setSize(WIDTH, HEIGHT);

        buttonHandler = new ButtonHandler();

        setLocation(Toolkit.getDefaultToolkit ().getScreenSize().width / 2 - WIDTH / 2,
                Toolkit.getDefaultToolkit ().getScreenSize().height / 2 - HEIGHT / 2);

        beginButton.addActionListener(buttonHandler);

    }

    public ImagePanel getImagePanel() {
        return imagePanel;
    }



    class ButtonHandler implements ActionListener {

        GameDifficulty gd;
        public void actionPerformed(ActionEvent e) {
            SizePrompt.this.setVisible(false);
                int rows = 0;
                int columns = 0;
                if (simple.isSelected()) {
                    rows = 2;
                    columns = 2;
                    gd = GameDifficulty.SIMPLE;
                }
                else if (easy.isSelected()) {
                    rows = 3;
                    columns = 4;
                    gd = GameDifficulty.EASY;
                }
                else if (medium.isSelected()) {
                    rows = 4;
                    columns = 5;
                    gd = GameDifficulty.MEDIUM;
                }
                else if (hard.isSelected()) {
                    rows = 6;
                    columns = 6;
                    gd = GameDifficulty.HARD;
                }
                frame = new MainFrame("Memory", rows, columns, SizePrompt.this, gd );
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
        }
    }
}

